package cn.seocoo.platform.contrast.service.impl;

import cn.seocoo.platform.car.dto.CarDto;
import cn.seocoo.platform.common.constant.ClassContants;
import cn.seocoo.platform.common.core.text.Convert;
import cn.seocoo.platform.contrast.domain.CarContrast;
import cn.seocoo.platform.contrast.mapper.CarContrastMapper;
import cn.seocoo.platform.contrast.service.ICarContrastService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 用户收藏车辆 服务层实现
 * 
 * @author wujian
 * @date 2020-01-02
 */
@Service
public class CarContrastServiceImpl implements ICarContrastService 
{
	@Autowired
	private CarContrastMapper carContrastMapper;

	/**
     * 查询用户收藏车辆信息
     * 
     * @param id 用户收藏车辆ID
     * @return 用户收藏车辆信息
     */
    @Override
	public CarContrast selectCarContrastById(Integer id)
	{
	    return carContrastMapper.selectCarContrastById(id);
	}
	
	/**
     * 查询用户收藏车辆列表
     * 
     * @param carContrast 用户收藏车辆信息
     * @return 用户收藏车辆集合
     */
	@Override
	public List<CarContrast> selectCarContrastList(CarContrast carContrast)
	{
	    return carContrastMapper.selectCarContrastList(carContrast);
	}
	
    /**
     * 新增用户收藏车辆
     * 
     * @param carContrast 用户收藏车辆信息
     * @return 结果
     */
	@Override
	public int insertCarContrast(CarContrast carContrast)
	{
	    return carContrastMapper.insertCarContrast(carContrast);
	}
	
	/**
     * 修改用户收藏车辆
     * 
     * @param carContrast 用户收藏车辆信息
     * @return 结果
     */
	@Override
	public int updateCarContrast(CarContrast carContrast)
	{
	    return carContrastMapper.updateCarContrast(carContrast);
	}

	/**
     * 删除用户收藏车辆对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteCarContrastByIds(String ids)
	{
		return carContrastMapper.deleteCarContrastByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<CarContrast> selectCarContrastByUserAndCarId(Integer appUserId, Integer carId) {
		return carContrastMapper.selectCarContrastByUserAndCarId(appUserId,carId);
	}

	/**
	 * @Author WuJian
	 * @Description 保存
	 * @Date 17:17 2020/1/2
	 * @Param [appUserId, carId]
	 * @return void
	 **/
	@Override
	public int save(Integer appUserId, Integer carId) {
		CarContrast car = new CarContrast();
		car.setAppUserId(appUserId);
		car.setCarInfoId(carId);
		car.setDelFlag(ClassContants.NO_DEL_FLAG);
		car.setCreateTime(new Date());
		return carContrastMapper.insertCarContrast(car);
	}

	/**
	 * @Author WuJian
	 * @Description //查询收藏的车辆信息
	 * @Date 18:26 2020/1/2
	 * @Param [pageNum, pageSize, appUserId]
	 * @return java.util.List<cn.seocoo.platform.car.dto.CarDto>
	 **/
	@Override
	public List<CarDto> getCarList(Integer pageNum, Integer pageSize, Integer appUserId) {
		PageHelper.startPage(pageNum == null? 1:pageNum,pageSize == null?10:pageSize);
		return carContrastMapper.getCarList(appUserId);
	}

	/**
	 * @Author WuJian
	 * @Description //取消收藏
	 * @Date 18:49 2020/1/2
	 * @Param [appUserId]
	 * @return int
	 **/
	@Override
	public int updateCarContrastForDel(Integer appUserId) {
		return carContrastMapper.updateCarContrastForDel(appUserId);
	}

	/**
	 * @Author WuJian
	 * @Description //清空
	 * @Date 19:03 2020/1/2
	 * @Param [id]
	 * @return int
	 **/
	@Override
	public int clearContrast(Integer id) {
		CarContrast carContrast = carContrastMapper.selectCarContrastById(id);
		carContrast.setDelFlag(ClassContants.IS_DEL_FLAG);
		return carContrastMapper.updateCarContrast(carContrast);
	}


}
